<?php
require_once('../../config.php');
require_once('security.php');

  if (isset($_POST['submit'])) { // Handle the form

    // Create the variable for ThisPage2
    $thispage2 = $_POST['thispage2'];

    // Create the link text
    $linktext2 = $_POST['linktext2'];
    $linktext2 = stripslashes($linktext2);
    // Trim whitespace at ends
    $linktext2 = trim($linktext2);
    // Strip out hyphens for page variable
    $thispage3 = str_replace("-", "", $thispage2);
    // Make lowercase and trim whitespace at ends
    $thispage3 = trim(strtolower($thispage3));

    // Define the HTML for a button in menu.php (as class template)
    //TG 19/7/09
    $buttonHTML = "\n" . '<?php $' . $thispage3 . ' = new Button;' . "\n" . ' $' . $thispage3 . '->ThisPage = $le_page;'."\n". '$' . $thispage3 . '->ThisPage2 = "' . $thispage2 . '";'."\n".'$' . $thispage3 . '->LinkText = "' . $linktext2 . '";'."\n". '$' . $thispage3 . '->basePath = "$wwwroot";'."\n".'$' . $thispage3 . '->Template2();'."\n".'?>'; 

    $button = $buttonHTML . "\n";

    // Path to the .php file (to write the template)
    $filename = "../includes/menu.php";

    // Write the contents
    $fp = fopen($filename, "a") or die("Couldn't open $filename.");
    fwrite($fp, $button);
    fclose($fp);

    // Feedback
    $response = "The file menu.php was updated.";
  }

?>

<?php $thisPage = "menu"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Create a new navigation button</title>
<meta name="robots" content="noindex,nofollow" />
<?php require_once('theme/admintheme.php');?>
</head>
<body>

<div id="wrap">



<?php include_once('navigation.php'); ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Existing page name (no file suffix)<br />
<input type="text" name="thispage2" id="thispage2" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['thispage2']; ?>" maxlength="60" />
<br />
Desired link text<br />
<input type="text" name="linktext2" id="linktext2" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['linktext2']; ?>" maxlength="60" />
<br />
<input type="submit" name="submit" value="Create button" />
</form>

<?php echo $response; ?>

<?php include_once('list-all.php'); ?>

<div style="clear: both;"></div>
</div>

</body>
</html>
